package sqlist;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class TestDemo {

    // 杨辉三角
    public static List<List<Integer>> generate(int numRows) {
        List<List<Integer>> ret = new ArrayList<>();
        List<Integer> one = new ArrayList<>();
        one.add(1);
        ret.add(one);
        // i是行数
        for (int i = 1; i < numRows; i++) {
            List<Integer> curRows = new ArrayList<>();
            curRows.add(1);
            // j代表这一行每一个元素
            for (int j = 1; j < i; j++) {
                List<Integer> preRows = ret.get(i-1);
                int x = preRows.get(j-1) + preRows.get(j);
                curRows.add(x);
            }
            curRows.add(1);
            ret.add(curRows);
        }
        return ret;
    }

    public static void main(String[] args) {

        List<List<Integer>> ret = generate(5);
        System.out.println(ret);

    }

    public static List<Character> func(String s1, String s2) {
        if(s1 == null || s2 == null) {
            return null;
        }
        if(s1.length() == 0 || s2.length() == 0) {
            return null;
        }

        List<Character> ret = new ArrayList<>();
        for (int i = 0; i < s1.length(); i++) {
            char ch = s1.charAt(i);
            if (!s2.contains(ch+"")) {
                ret.add(ch);
            }
        }
        return ret;
    }

    public static void main6(String[] args) {
        String s1 = "welcome to jiangxi";
        String s2 = "come";
        List<Character> ret = func(s1, s2);
        //System.out.println(ret);
        for(char ch : ret) {
            System.out.print(ch);
        }
        System.out.println();
    }

    public static void main5(String[] args) {
        ArrayList<Integer> arrayList = new ArrayList<>();
        arrayList.add(0,1);
        arrayList.add(1,2);
        arrayList.add(2,199);
        arrayList.add(3,299);
        arrayList.add(4,399);

        List<Integer> list = arrayList.subList(1,3);// [  )
        System.out.println(list);// [2,199]

        list.set(0,50);
        System.out.println(list);
        System.out.println("原来的list"+arrayList);

        System.out.println("=================");
        for (int i = 0; i < arrayList.size(); i++) {
            System.out.print(arrayList.get(i)+" ");
        }
        System.out.println();
        System.out.println("==================");
        for (Integer x : arrayList) {
            System.out.print(x+" ");
        }
        System.out.println();
        System.out.println("=========使用迭代器=========");
        Iterator<Integer> it = arrayList.iterator();
        while (it.hasNext()) {
            System.out.print(it.next()+" ");
        }
    }

    public static void main4(String[] args) {
        ArrayList<Integer> arrayList = new ArrayList<>();
        arrayList.add(0,1);
        arrayList.add(1,2);
        arrayList.add(2,3);
        arrayList.add(3,99);
        arrayList.add(99);
        arrayList.add(99);
        System.out.println(arrayList);

        arrayList.remove(0);
        System.out.println(arrayList);

//        arrayList.remove(new Integer(99));
//        System.out.println(arrayList);

        int index = arrayList.lastIndexOf(new Integer(99));//从后往前找的第一个下标
        System.out.println(index);

//        ArrayList<Integer> arrayList2 = new ArrayList<>();
//        arrayList2.addAll(arrayList);//尾差arrayList中的元素
//        arrayList2.add(90);
//        System.out.println(arrayList2);
    }

    public static void main3(String[] args) {
        ArrayList<Integer> arrayList = new ArrayList<>();
        arrayList.add(1);
        arrayList.add(2);
        arrayList.add(3);
        arrayList.add(4);
        System.out.println(arrayList.size());
        System.out.println(arrayList.get(1));
        System.out.println("===================");
        //使用其他的集合，来构造当前的list
        ArrayList<Integer> arrayList2 = new ArrayList<>(arrayList);//此时arrayList是Integer的子类
        arrayList2.add(9);
        System.out.println(arrayList2);

        ArrayList<Integer> arrayList3 = new ArrayList<>(15);//指定容量

    }

    public static void main2(String[] args) {
        MyArraylist myArraylist = new MyArraylist();
        myArraylist.add(0, 1);
        myArraylist.add(1, 2);
        myArraylist.add(2, 3);
        myArraylist.add(3, 4);
        myArraylist.add(4, 5);
        myArraylist.add(0, 99);
        myArraylist.add(3,88);
        myArraylist.display();
        myArraylist.set(0, 199);
        myArraylist.display();
    }

    public static void main1(String[] args) {
        MyArraylist myArraylist = new MyArraylist();
        myArraylist.add(0, 1);
        myArraylist.add(1, 2);
        myArraylist.add(2, 3);
        myArraylist.add(3, 4);
        myArraylist.add(4, 5);
        myArraylist.add(0, 99);
        myArraylist.add(3,88);
        myArraylist.display();
        System.out.println("==========================");
        int ret = myArraylist.get(2);
        System.out.println(ret);

    }
}
